package top.lidee.module.clientApi.twice.applet;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.lidee.common.service.twice.applet.MtStoreCateService;
import top.lidee.framework.result.PageUtils;
import top.lidee.framework.result.ResponseResult;
import top.lidee.repository.model.twice.pojo.applet.MtStoreCateEntity;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


/**
 * 店铺主营行业分类表
 *
 * @author zhangzhan
 * @email 52194440@qq.com
 * @date 2024-09-25 14:40:51
 */
@Api("店铺主营行业分类表")
@RestController
@RequestMapping("/applet/mtstockcate")
public class MtStoreCateController {
    @Autowired
    private MtStoreCateService mtStoreCateService;

    /**
     * 商户1级分类列表
     */
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @ApiOperation(value = "店铺主营行业分类表列表")
    public ResponseResult list() {
        List<MtStoreCateEntity> list = mtStoreCateService.list(Wrappers.<MtStoreCateEntity>lambdaQuery()
                .eq(MtStoreCateEntity::getCatLevel, 1));
        return ResponseResult.okResult(list);
    }

    /**
     * 根据1级分类查询对应2级分类
     */
    @RequestMapping(value = "/getSecondaryCateByOne/{cateId}", method = RequestMethod.GET)
    @ApiOperation(value = "根据1级分类查询对应2级分类")
    public ResponseResult getSecondaryCateByOne(@PathVariable("cateId") Integer cateId) {
        ResponseResult responseResult = mtStoreCateService.getSecondaryCateByOne(cateId);
        return responseResult;
    }


    /**
     * 信息
     */
    @RequestMapping(value = "/info/{categoryId}", method = RequestMethod.GET)
    @ApiOperation(value = "店铺主营行业分类表信息")
    public ResponseResult info(@PathVariable("categoryId") Long categoryId) {
        MtStoreCateEntity mtStockCate = mtStoreCateService.getById(categoryId);

        return ResponseResult.okResultPage("MtStockCate", mtStockCate);
    }

    /**
     * 保存
     */
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    @ApiOperation(value = "店铺主营行业分类表保存")
    public ResponseResult save(@RequestBody MtStoreCateEntity mtStockCate) {
        mtStoreCateService.save(mtStockCate);

        return ResponseResult.ok();
    }

    /**
     * 修改
     */
    @RequestMapping(value = "/update", method = RequestMethod.PUT)
    @ApiOperation(value = "店铺主营行业分类表修改")
    public ResponseResult update(@RequestBody MtStoreCateEntity mtStockCate) {
        mtStoreCateService.updateById(mtStockCate);

        return ResponseResult.ok();
    }

    /**
     * 删除
     */
    @RequestMapping(value = "/delete", method = RequestMethod.DELETE)
    @ApiOperation(value = "店铺主营行业分类表删除")
    public ResponseResult delete(@RequestBody Long[] categoryIds) {
        mtStoreCateService.removeByIds(Arrays.asList(categoryIds));

        return ResponseResult.ok();
    }

}
